package cc.autoapi.pucong.auto.flow.provider.aop.entity.vo;

import lombok.Data;

import java.io.Serializable;

/**
 * 项目aop 执行关联规则信息vo
 *
 * @author pucong
 * @url https://gitee.com/pucong
 * @create 2023-11-21
 */
@Data
public class ProjectAopRuleExecVo implements Serializable {

    private static final long serialVersionUID = 1L;

    private String uuid;
    /**
     * 类型 0:正则匹配，1:包含匹配，2:不包含匹配
     */
    private Integer aopType;

    private String aopValue;

    public Boolean checkRule(String code) {
        if (aopType == 0) {
            if (code.matches(aopValue)) {
                return true;
            }
        } else {
            String[] split = aopValue.split(",");
            for (String value : split) {
                if (aopType == 1 && code.contains(value)) {
                    return true;
                } else if (aopType == 2 && code.contains(value)) {
                    return false;
                }
            }
        }
        return false;
    }
}
